/**
 * 

 */
package edu.vt.ece.rt.dstm.contention;

import java.io.IOException;

import edu.vt.ece.rt.QR;
import edu.vt.ece.rt.dstm.Context;
import edu.vt.ece.rt.quorum.util.Names;

/**
 * 
 * @author Sudhanshu
 *
 */
public class ContentionManager {
	static AbstractContentionPolicy cp;
	
	public static void init(){
		try {
			cp = (AbstractContentionPolicy) Class.forName("edu.vt.ece.rt.dstm.contention." + System.getProperty(Names.contentionPolicy)).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static int resolve(Context c1, Context c2){
		if(cp == null){
			ContentionManager.init();
		}
		return cp.resolve(c1, c2);
	}
	
	public static void main(String[] args) {
		try {
			QR.loadConfig();
		} catch (IOException e) {
			e.printStackTrace();
		}
		Context c = new Context();
		ContentionManager.resolve(c, c);
	}
}
